﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using YiSha.Util;
using YiSha.Util.Extension;
using YiSha.Util.Model;
using YiSha.Entity.QixingManage;
using YiSha.Model.Param.QixingManage;
using YiSha.Service.QixingManage;
using YiSha.Model.Result;

namespace YiSha.Business.QixingManage
{
    /// <summary>
    /// 创 建：admin
    /// 日 期：2023-03-28 20:22
    /// 描 述：功能模块业务类
    /// </summary>
    public class ModuleCategoryBLL
    {
        private ModuleCategoryService moduleCategoryService = new ModuleCategoryService();

        #region 获取数据
        public async Task<TData<List<ModuleCategoryEntity>>> GetList(ModuleCategoryListParam param)
        {
            TData<List<ModuleCategoryEntity>> obj = new TData<List<ModuleCategoryEntity>>();
            obj.Data = await moduleCategoryService.GetList(param);
            obj.Total = obj.Data.Count;
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData<List<ModuleCategoryEntity>>> GetPageList(ModuleCategoryListParam param, Pagination pagination)
        {
            TData<List<ModuleCategoryEntity>> obj = new TData<List<ModuleCategoryEntity>>();
            obj.Data = await moduleCategoryService.GetPageList(param, pagination);
            obj.Total = pagination.TotalCount;
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData<List<ZtreeInfo>>> GetModuleCategoryTreeListJson()
        {
            var obj = new TData<List<ZtreeInfo>>();
            obj.Data = new List<ZtreeInfo>();

            List<ModuleCategoryEntity> list = await moduleCategoryService.GetList();

            foreach (ModuleCategoryEntity menu in list)
            {
                obj.Data.Add(new ZtreeInfo
                {
                    id = menu.Id,
                    pId =0,
                    name = menu.module_category_name
                });
            }

            obj.Tag = 1;
            return obj;
        }
        

        public async Task<TData<ModuleCategoryEntity>> GetEntity(long id)
        {
            TData<ModuleCategoryEntity> obj = new TData<ModuleCategoryEntity>();
            obj.Data = await moduleCategoryService.GetEntity(id);
            if (obj.Data != null)
            {
                obj.Tag = 1;
            }
            return obj;
        }
        #endregion

        #region 提交数据
        public async Task<TData<string>> SaveForm(ModuleCategoryEntity entity)
        {
            TData<string> obj = new TData<string>();
            await moduleCategoryService.SaveForm(entity);
            obj.Data = entity.Id.ParseToString();
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData> DeleteForm(string ids)
        {
            TData obj = new TData();
            await moduleCategoryService.DeleteForm(ids);
            obj.Tag = 1;
            return obj;
        }
        #endregion

        #region 私有方法
        #endregion
    }
}
